package com.two.service.permission.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.two.common.entity.RolePermission;
import com.two.common.util.CommonResult;
import com.two.service.permission.mapper.RolePermissionMapper;
import com.two.service.permission.service.IRolePermissionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 角色权限 服务实现类
 * </p>
 *
 * @author 汪瑞明
 * @since 2022-08-31
 */
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements IRolePermissionService {

    @Override
    @Transactional
    public CommonResult yes(Integer roleid, List<String> ids) {
        // 删除roleid对应的权限
        QueryWrapper<RolePermission> wrapper = new QueryWrapper<>();
        wrapper.eq("roleid",roleid);
        this.remove(wrapper);

        System.out.println(ids);
        // 添加新的权限
        List<RolePermission> collect = ids.stream().map(item -> new RolePermission(null,roleid,item,false, LocalDateTime.now(),LocalDateTime.now())).collect(Collectors.toList());
        this.saveBatch(collect);
        return new CommonResult(2000,"分配成功",null);
    }
}

















